package data.visu.utils;

import data.Constants;



/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class TimeHMSConvertor {
	
	public static int[] frame2HMS(int frame){
		int seconds = (int) ((frame / Constants.FPS) % 60);
		int minutes = (int) ((frame / Constants.FPS) / 60);
		int hours = (int)((frame / Constants.FPS) / 3600);
		minutes = minutes%60;
		int[] res = new int[3];
		res[0]=hours;
		res[1]=minutes;
		res[2]=seconds;
		return res;
	}
	
	public static String frame2HMSString(int frame){
		int seconds = (int) ((frame / Constants.FPS) % 60);
		int minutes = (int) ((frame / Constants.FPS) / 60);
		int hours = (int)((frame / Constants.FPS) / 3600);
		minutes = minutes%60;
		
		if(seconds==0 && minutes==0){
			return hours+"h";
		}
		if(seconds==0){
			return minutes+"\'";
		}
		
		return minutes+"\'"+seconds+"\"";
	}
	
	public static int HMS2Frame(int[] HMS){
		return (HMS[0]*3600*Constants.FPS + HMS[1]*60*Constants.FPS + HMS[2]*Constants.FPS);
	}
	
	public static int HMS2Frame(int hours, int minutes, int seconds){
		return (hours*3600*Constants.FPS + minutes*60*Constants.FPS + seconds*Constants.FPS);
	}

	public static int closestFrameFromScreen(double selMinValue) {
		return (int)((selMinValue)+.5);
	}
	
}
